home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: accessing structures via pointers
- Date: Mon, 08 Apr 96 20:13:54 GMT
- Organization: none
- Message-ID: <828994434snz@genesis.demon.co.uk>
- References: <1996Apr8.144012.25767@leeds.ac.uk>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Apr8.144012.25767@leeds.ac.uk>
- csyamc@scs.leeds.ac.uk "A M Casey" writes:
-
- >Hi I'm calling the function getgrent(), which resturns a structure
- >as defined in grp.h, ie
- >
- > struct group {
- > char *gr_name; /* the name of the group */
- > char *gr_passwd; /* the encrypted group password */
- > gid_t gr_gid; /* the numerical group ID */
- > char **gr_mem; /* vector of pointers to member names */
- > };
- >the trouble is it returns a pointer to the structure:
- >
- >struct group *getgrent(void);
- >
- >
- >and I havent got a clue how to access it. I've lookied at the faq, but
- >I'm still stuck.
-
- The FAQ doesn't generally cover basic language topics that are explained
- in any C language textbook.
-
- >I need something like
- >
- >printf("the group name is %s\n",tempgroup.gr_name);
- >
- >but that doesnt work because tempgroup is a pointer.
- >
- >How do I do this?
-
- If tempgroup is a pointer to a structure then *tempgroup is a structure
- and (*tempgroup).gr_name gives you the particular member. The parentheses
- are there because . has higher precedence than *. The language provides a
- shorter way of writing the same thing, that is tempgroup->gr_name.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-